import time

from selenium.webdriver.common.by import By

from Common.Unity import ForumDriver


class TestLogin:
    driver: ""
    url: ""

    def __init__(self):
        self.url = "http://127.0.0.1:9580/sign-in.html"
        self.driver = ForumDriver.driver
        self.driver.get(self.url)

        # 成功登录的测试用例

    def LoginSucTest(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("heyu")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("heyu123...")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        # 能找首页的字体即可
        time.sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#article_list_board_title")
        print("登录成功测试成功")

    # 测试密码错误的用例
    def LoginFileTest1(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("heyu")
        # 错误的密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("12345678")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        print("错误的密码测试完成")

        # 测试账号错误的用例
    def LoginFileTest2(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("xiaoyu")
        # 错误的密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("heyu123...")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        print("错误的账号测试完成")

        # 测试账号密码错误的用例

    def LoginFileTest3(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("xiaoyu")
        # 错误的密码
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        print("错误的密码账号测试完成")

# login = TestLogin()
# login.LoginSucTest()
# # login.driver.back()
# # login.LoginFileTest1()
# # login.LoginFileTest2()
# # login.LoginFileTest3()
# login.driver.quit()
